package com.yxx.mapper;

import com.github.pagehelper.Page;
import com.yxx.annotation.AutoFill;
import com.yxx.medicinecommon.enumeration.OperationType;
import com.yxx.medicinepojo.dto.ChineseMedicinePageQueryDTO;
import com.yxx.medicinepojo.entity.ChineseMedicine;
import com.yxx.medicinepojo.entity.ChineseWesternMedicine;
import com.yxx.medicinepojo.vo.ChineseMedicineVO;
import com.yxx.medicinepojo.vo.ChineseWesternMedicineVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author yuxiangxun
 * @date 2024/9/7
 * @apiNote
 */
@Mapper
public interface ChineseMedicineMapper {

    /**
     * 中药分页查询
     * @param chineseMedicinePageQueryDTO
     * @return
     */
    Page<ChineseMedicineVO> pageQueryChineseMedicine(ChineseMedicinePageQueryDTO chineseMedicinePageQueryDTO);

    /**
     * 根据分类id查询中药
     * @param chineseMedicineVO
     * @return
     */
    List<ChineseMedicineVO> list(ChineseMedicineVO chineseMedicineVO);

    /**
     * 新增药品
     * @param chineseMedicine
     */
    @AutoFill(value = OperationType.INSERT)
    void insert(ChineseMedicine chineseMedicine);

    /**
     * 修改药品
     * @param chineseMedicine
     */
    @AutoFill(value = OperationType.UPDATE)
    void update(ChineseMedicine chineseMedicine);

    /**
     * 回显数据，根据id查询中药信息
     * @param id
     * @return
     */
    @Select("select * from chinese_western_medicine where id = #{id} and medicine_category_id = 1  " )
    ChineseMedicine ChineseMedicineSelectUpdateById(Long id);

    /**
     * 根据药品id查询中药信息
     * @param id
     * @return
     */
    @Select("select * from chinese_western_medicine where id = #{id}")
    ChineseMedicine ChineseMedicineById(Long id);

    /**
     * 根据药品ids集合删除药中药信息
     * @param ids
     */
    void deleteByIds(List<Long> ids);

    /**
     * 组合药药品表+中西药表联立，根据组合药id获取中药信息（集合）
     * @param id
     * @return
     */
    @Select("select cwm.* from chinese_western_medicine cwm left join setmedicine_medicine sm on cwm.id = sm.medicine_id where sm.setmedicine_id = #{id}")
    List<ChineseWesternMedicine> getChineseWesternMedicineStatusList(Long id);


}
